//my_list.c
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include "my_list.h"
//全局函数，把元素添加进列表
static void CopyToNode(Node *pNode,iTem item)
{
    pNode->item = item;
}
//初始化List对象
void InitializeList(List *plist)
{
    plist->head = NULL;
    plist->size = 0;
}
//确认列表是否为空
bool ListIsEmpty(const List* plist)
{
    if(plist == NULL)
    return true;
    return false;
}
//确认列表是否已满
bool ListIsFull(const List* plist)
{
    plist = (List*)malloc(sizeof(List));
    if(plist == NULL)
    return true;
    else
    return false;
}
unsigned int ListItemCount( List* plist)
{
    unsigned int count = 0;
    while (plist->head != NULL)
    {
        count++;
        plist->head = plist->head->next;
    }
    return count;
}
//添加元素，由于我们实现的是单向链表，所以使用从尾部添加
bool AddItem(iTem item,List* plist)
{
    Node *pNew,*temp;
    pNew = (Node*)malloc(sizeof(Node));
    if(pNew == NULL) return false;
    CopyToNode(pNew,item);
    temp = pNew->next;
    if(plist->head != NULL)
    {
        while(plist->head->next != NULL)
        {
            plist->head = plist->head->next;
        }
        plist->head->next = pNew;
    }
    else
    {
        plist->head = pNew;
    }
    return true;
}
//显示列表中的元素
void ShowListItem(const List* plist)
{
    Node* pNode = plist->head;
    while(pNode != NULL)
    {
        printf("%s:%s\n",
               pNode->item.Name,pNode->item.TelNumber);
        pNode = pNode->next;
    }
}
//释放内存
void FreetheList(List* plist)
{
    while(plist->head != NULL)
    {
        Node* pNode;
        pNode = plist->head->next;
        free(plist->head);
        plist->head = pNode;
    }
}